package cn.kgc.nnniiiooo.controller;

import cn.kgc.nnniiiooo.common.Result;
import cn.kgc.nnniiiooo.pojo.UserInfo;
import cn.kgc.nnniiiooo.service.UserInfoService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@CrossOrigin
public class UserInfoController {
    @Resource
    private UserInfoService userInfoService;
    @GetMapping("/getuserinfo")
    @RequiresPermissions("userInfo:view") // 权限管理.
    public Result getuserinfo(String username){
        UserInfo userInfo = userInfoService.findByUsername(username);
        return Result.ok(userInfo);
    }

    /**
     * 简单模拟从数据库添加用户信息成功
     *
     * @return
     */
    @PostMapping("/userAdd")
    @RequiresPermissions("userInfo:add")
    public String addUserInfo() {
        return "addUserInfo success!";
    }

    /**
     * 简单模拟从数据库删除用户成功
     *
     * @return
     */
    @DeleteMapping("/userDelete")
    @RequiresPermissions("userInfo:delete")
    public String deleteUserInfo() {
        return "deleteUserInfo success!";
    }

    @RequestMapping("/403")
    public String unauthorizedRole(){
        System.out.println("------没有权限-------");
        return "403";
    }
}
